//! Literal types.

use super::ValueType;

#[derive(Copy, Clone, Debug)]
pub enum LiteralValue {
    /// This is meant to be an absence of a value or something "nullish".
    Void,

    U8(u8),
    I64(i64),
    U64(u64),

    /// Represented as a u64 here because we don't know what the target is going to be.
    USize(u64),

    /// Represented as a i64 here because we don't know what the target is going to be.
    ISize(i64),

    Bool(bool),
}

impl LiteralValue {
    pub fn ty(&self) -> ValueType {
        match self {
            Self::Void => ValueType::Void,
            Self::U8(_) => ValueType::U8,
            Self::I64(_) => ValueType::I64,
            Self::U64(_) => ValueType::U64,
            Self::USize(_) => ValueType::USize,
            Self::ISize(_) => ValueType::ISize,
            Self::Bool(_) => ValueType::Bool,
        }
    }
}

impl From<()> for LiteralValue {
    fn from(_value: ()) -> Self {
        LiteralValue::Void
    }
}

impl From<u8> for LiteralValue {
    fn from(value: u8) -> Self {
        LiteralValue::U8(value)
    }
}

impl From<i64> for LiteralValue {
    fn from(value: i64) -> Self {
        LiteralValue::I64(value)
    }
}

impl From<u64> for LiteralValue {
    fn from(value: u64) -> Self {
        LiteralValue::U64(value)
    }
}

impl From<bool> for LiteralValue {
    fn from(value: bool) -> Self {
        LiteralValue::Bool(value)
    }
}
